﻿using Abp.Quartz.Quartz;
using ACN.Mail.Jobs;
using Quartz;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace ACN.Mail.Web.Controllers
{
    public class HomeController : MailControllerBase
    {
        private readonly IQuartzScheduleJobManager _jobManager;
        public HomeController(IQuartzScheduleJobManager jobManager)
        {
            _jobManager = jobManager;
        }

        public ActionResult Index()
        { 
            return View("~/App/Main/views/layout/layout.cshtml"); //Layout of the angular application.
        }
        public async Task<ActionResult> ScheduleJob()
        {
            await _jobManager.ScheduleAsync<MyLogJob>(
                job =>
                {
                    job.WithIdentity("MyLogJobIdentity", "MyGroup")
                        .WithDescription("A job to simply write logs.");
                },
                trigger =>
                {
                    trigger.StartNow()
                        .WithSimpleSchedule(schedule =>
                        {
                            schedule.RepeatForever()
                                .WithIntervalInSeconds(5)
                                .Build();
                        });
                });

            return Content("OK, scheduled!");
        }
    }
}